<template>
  <div class="good-list-item" @click="itemClick" v-if="Object.keys(goodsItem).length !== 0">
    <img v-lazy="showImg" alt="" />
    <div class="info">
      <p>{{ goodsItem.title }}</p>
      <span class="price"> {{ "￥" + goodsItem.price }} </span><span class="collect">{{ goodsItem.cfav }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "GoodsListItem",
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  computed: {
    showImg() {
      return this.goodsItem.image || this.goodsItem.show.img;
    },
  },
  methods: {
    itemClick() {
      let url = this.goodsItem.iid;
      if (url) {
        this.$router.push("/detail/" + url);
      }
    },
  },
};
</script>

<style scoped>
.good-list-item {
  position: relative;
  width: 48%;
  box-sizing: border-box;
  text-align: center;
  padding-bottom: 40px;
  margin-bottom: 5px;
}
.good-list-item img {
  width: 100%;
  border-radius: 5px;
}
.good-list-item p {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
  margin-top: 2px;
}
.good-list-item .price {
  color: var(--color-high-text);
  font-weight: 700;
  padding-right: 30px;
}
.good-list-item .collect {
  position: relative;
}
.good-list-item .collect::before {
  position: absolute;
  left: -14px;
  content: "";
  width: 12px;
  height: 12px;
  background: url("~assets/img/home/Collection.svg") 0 0/14px 14px;
}
.info {
  width: 100%;
  position: absolute;
  bottom: 5px;
}
</style>
